﻿#pragma once

#include<Windows.h>
#include<stdlib.h>
#include<locale.h>
#include<stdbool.h>
#include<time.h>
#include<stdio.h>
#include<mmstream.h>
#pragma comment(lib,"winmm.lib")

#define WALL L'■'
#define FOOD L'★'
#define BODY L'○'
#define HEAD L'●'

#define FOOD_COLOR  11 
#define SNAKE_COLOR 10 
#define WALL_COLOR  14
#define TEXT_COLOR  12

#define S_NODE_NUM 3
#define S_POS_X 28
#define S_POS_Y 20

//枚举蛇方向所有情况
enum SnakeDirect
{
	UP = 1,
	DOWN,
	LEFT,
	RIGHT,
};

//枚举游戏输赢的状况
enum SnakeState
{
	GAME_NORMAL,
	GAME_FINISH,
	KILL_BYSELF,
	KILL_BYWALL,
};

//定义一个蛇身结点
struct SnakeNode
{
	short x;
	short y;
	struct SnakeNode* next;
};

//将这个游戏的数据都由一个结构体妥善管理
typedef struct Snake
{
	struct SnakeNode* _Snake;
	struct SnakeNode* _Food;
	enum SnakeDirect _Direct;
	enum SnakeState _State;
	int _FoodScore;
	int _SnakeSpeed;
	int _Score;
}Snake, * pSnake;

//定位光标坐标
void SetPos(short x, short y);

//修改控制台输出颜色
void ConsoleTextColor(WORD wAttributes);

//游戏开始
pSnake GameBegin();

//播放音乐
void MusicPlay(wchar_t* FILENAME, bool x, int audio);

//设置控制台信息
void SetConloleInfo();

//模拟阻塞
void Pause();

//制作简易的欢迎界面
void WelcomeCover();

//制作一个进度条
//void ProgressBar();
//做不出来，呜呜

//制作围墙
void MakeWall();

//生成一条蛇并初始化
void SnakeInit(pSnake snake);

//随机产生食物
void FoodCreat(pSnake snake);

//在控制台右侧打印帮助信息
void HelpInfo();

//打印分数
void ScorePrint(pSnake snake);

//根据按键修改蛇的方向
#define KEY_STATE(key) (((GetAsyncKeyState(key)) & 0x1)?1:0)
void ModifySnakeDirect(pSnake snake);

//蛇的移动
void SnakeMove(pSnake snake);

//判定下一个位置是不是食物
bool FoodJudg(pSnake snake, struct SnakeNode* NextNode);

//是否撞到墙体
void KillSelfByWall(pSnake snake);

//是否撞到自己
void KillSelfBySelf(pSnake snake);

//游戏运作中
void GameRun(pSnake snake);

//游戏结束
void GameEnd(pSnake snake);